package com.erp.servlet;

import com.erp.bean.Commodity;
import com.erp.bean.Entrepot;
import com.erp.bean.Inventory;
import com.erp.service.CommodityService;
import com.erp.service.EntrepotService;
import com.erp.service.InventoryService;
import com.erp.service.impl.CommodityServiceImpl;
import com.erp.service.impl.EntrepotServiceImpl;
import com.erp.service.impl.InventoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author lyb
 * 创建分仓显示控制器
 */
@WebServlet("/inventorylittle.action")
public class InventoryLittleServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收仓库编号
        String entid=req.getParameter("entid");
        //创建库存业务逻辑对象
        int ent=Integer.valueOf(entid);
        InventoryService inventoryService=new InventoryServiceImpl();
        //调用业务逻辑方法,查询所有对象
        List<Inventory> list=inventoryService.findAll();
        //创建商品业务逻辑对象
        CommodityService commodityService=new CommodityServiceImpl();
        List<Commodity> Commoditys= commodityService.findAll();
        //创建仓库业务逻辑对象
        EntrepotService entrepotService=new EntrepotServiceImpl();
        List<Entrepot> Entrepots=entrepotService.findAll();
        //将结果放入作用域中
        req.setAttribute("entid",ent);
        req.setAttribute("list",list);
        req.setAttribute("Commoditys",Commoditys);
        req.setAttribute("Entrepots",Entrepots);

        //转发到显示页面
        req.getRequestDispatcher("inventorylist.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
